load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@rules_zig//zig:defs.bzl", "zig_library", "zig_shared_library")

zig_shared_library(
    name = "zmlxrocm",
    # Use Clang's compiler-rt, but disable stack checking
    # to avoid requiring on the _zig_probe_stack symbol.
    zigopts = ["-fno-stack-check"],
    main = "zmlxrocm.zig",
    shared_lib_name = "libzmlxrocm.so.0",
    visibility = ["@libpjrt_rocm//:__subpackages__"],
    deps = ["//stdx"],
)

alias(
    name = "hipblaslt",
    actual = "@libpjrt_rocm//:hipblaslt",
)

alias(
    name = "gfx",
    actual = "@libpjrt_rocm//:gfx",
)

cc_library(
    name = "empty",
    defines = ["ZML_RUNTIME_ROCM_DISABLED"],
)

cc_library(
    name = "libpjrt_rocm",
    defines = ["ZML_RUNTIME_ROCM"],
    deps = ["@libpjrt_rocm"],
)

zig_library(
    name = "rocm",
    import_name = "runtimes/rocm",
    main = "rocm.zig",
    visibility = ["//visibility:public"],
    deps = [
        "//pjrt",
    ] + select({
        "//runtimes:rocm.enabled": [
            ":libpjrt_rocm",
            "//async",
            "//stdx",
            "@rules_zig//zig/runfiles",
        ],
        "//conditions:default": [":empty"],
    }),
)

filegroup(
    name = "layers",
    srcs = [],
    visibility = ["//visibility:public"],
)
